<?php
defined('_JEXEC') or die('Restricted access');
$db = JFactory::getDBO();
$query = "SELECT a.auction_date, p.katno, p.model, p.stand, p.register_day, p.view_day, p.registry, p.km, p.comment FROM #__auction a INNER JOIN #__pr_product p ON a.product_id = p.id WHERE a.closed = 0 ORDER BY p.katno";
$db->setQuery($query);
$pros = $db->loadObjectList();

$i = 1;

$document = JFactory::getDocument();
$document->setTitle('Dansk Automobil Børs - Cars list');
?>
<style>
.tb_print td{
	padding:0;
}
</style>
<div style="width:1500px; margin:0px auto;">
    <table style="width: 100%; color:#303030; border-bottom:2px silver solid; margin-bottom:0;" cellpadding="0" cellspacing="0">
        <tr>
            <td style="vertical-align:bottom; font-weight:bold;font-size:20px;">Auktionskatalog for auktionen den <?php echo $pros[0]->auction_date;?></td>
            <td colspan="4">&nbsp;</td>
        </tr>
        
    </table>
    
    <table style="width: 100%; margin:5px 0; font-size:16px;" class="tb_print">
        <tr>
            <td width="5%"><strong>Kat.No</strong></td>
            <td width="33%"><strong>Mærke/Model</strong></td>
            <td width="5%" style="text-align:center;"><strong>Stand</strong></td>
            <td width="6%" style="text-align:center;"><strong>1.Reg</strong></td>
            <td width="7%" style="text-align:center;"><strong>S.Syn</strong></td>
            <td width="5%" style="text-align:center;"><strong>Snes</strong></td>
            <td width="7%"><strong>Km.stand</strong></td>
            <td width="32%"><strong>Bemærkninger</strong></td>
        </tr>
        <?php foreach($pros as $pro){
			if($i%3 == 1) echo '<tr><td colspan="8"><hr></td></tr>';	
		?>
        <tr>
            <td><?php echo $pro->katno;?></td>
            <td><?php echo $pro->model;?></td>
            <td style="text-align:center;" ><?php echo $pro->stand;?></td>
            <td style="text-align:center;"><?php echo $pro->register_day;?></td>
            <td style="text-align:center;"><?php echo $pro->view_day;?></td>
            <td style="text-align:center;"><?php if($pro->registry) echo 'Ja'; else echo 'Nej';?></td>
            <td><?php echo $pro->km;?></td>
            <td><?php echo $pro->comment;?></td>
        </tr>
       	<?php $i++;}?>
        
    </table>
    
</div>
<script language="javascript">
	window.print();
	window.onfocus = function() { window.close(); }
</script>